<?php
namespace Tbf\Bundle\ConfigBundle\Tests;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Tbf\Bundle\ConfigBundle\ConfigManager;

class ConfigManagerTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var \Symfony\Component\DependencyInjection\Container
     */
    protected $container;
    /**
     * @var \Symfony\Component\EventDispatcher\EventDispatcher
     */
    protected $dispatcher;

    public function getObj()
    {
        $this->container = new Container();
        $this->dispatcher = new EventDispatcher();
        $config_manager = new ConfigManager($this->container,null,$this->dispatcher);

        return $config_manager;
    }

    public function testSetGetParameter()
    {
        $obj = $this->getObj();
        $obj->setParameter('alumni.birthday_email_open','1');
        $this->assertEquals('1',$obj->getParameter('alumni.birthday_email_open'));
        $this->assertEquals(false,$this->container->hasParameter('alumni.birthday_email_open'));
    }

    public function testGetParameter()
    {
        $obj = $this->getObj();
        $this->container->setParameter('testk1','testv2');
        $this->assertEquals('testv2',$obj->getParameter('testk1'));
    }

    public function testGetManageParameterList()
    {
        $obj = $this->getObj();
        $obj->setParameter('alumni.birthday_email_open','1');
        $obj->setParameter('alumni.reply_to_email','1@1.com');
        $obj->setParameter('alumni.return_email','2@1.com');
        $expect = array(
            'alumni.birthday_email_open'=>'1',
            'alumni.reply_to_email'=>'1@1.com',
            'alumni.return_email'=>'2@1.com',
        );
        $this->assertEquals($expect,$obj->getManageParameterList());
    }

    public function testGetManageNameList()
    {
        $obj = $this->getObj();
        $expect = array(
            'alumni.birthday_email_open',
            'alumni.reply_to_email',
            'alumni.return_email',
        );
        $this->assertEquals($expect,$obj->getManageNameList());
    }

}
